import { playDetail } from '@/api';

const state = {
  // 控制loading的显示隐藏
  spinning: true,
  // 歌单简介
  playList: {},
  // 歌单列表
  privileges: [],
  // 控制骨架屏的显示
  loading: true,
  // 判断是否需要播放歌曲
  isPlayed: false,
  // 如果时歌手详情页隐藏sider和footer
  hide: false,
  // 判断是否登录弹出登录框
  showModal: false,
  // 控制歌词的loading
  isLoad: false,
  // 记录搜索详情操作
  operation: {
    current: 0,
    page: 1,
    top: 0
  }
}

const mutations = {
  SPINNING(state, show) {
    state.spinning = show;
  },
  // 歌单详情信息
  PLAYDETAIL(state, data) {
    state.playList = data.playlist;
    state.privileges = data.privileges;
  },
  // 控制骨架屏的显示
  LOADING(state, show) {
    state.loading = show;
  },
  // 控制是否需要播放歌曲
  ISPLAYED(state, play) {
    state.isPlayed = play;
  },
  // 控制sider和footer的显示隐藏
  HIDE(state, show) {
    state.hide = show;
  },
  SHOWMODAL(state, show) {
    state.showModal = show;
  },
  ISLOAD(state, show) {
    state.isLoad = show;
  },
  OPERATION(state, o) {
    state.operation = o;
  }
}

const actions = {
  async getPlayDetail({commit}, id) {
    const list = await playDetail(id);
    if (list.data.code === 200) {
      commit('PLAYDETAIL', list.data);
      let timer = setTimeout(() => {
        if (!state.loading) clearTimeout(timer);
        commit('LOADING', false);
      }, 500);
    }
  },
  // 获取二维码
  // async getqrCode({ commit }) {
  //   const key = (await qrKey()).data.data.unikey;
  //   commit('QRKEY', key);
  //   const qr = (await qrCreate(key)).data.data.qrimg;
  //   commit('QRCODE', qr);
  // }
}

const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}